package com.vint.leetcode;

/*
 * 24点游戏，给四个数，+-/()
 */
public class Leetcode679 {
    public static final double EPISON = 0.000001;
    public boolean judgePoint24(int[] nums) {
        if(null == nums || nums.length != 4){
            return false;
        }
        for(int i=0; i<4; i++){
            for(int j=i+1; j<4;j++){
                //if(threeJudge())
            }
        }

        return false;
    }
    public boolean threeJudge(double t1, double t2, double t3){

        return twoJudge(t1*t2,t3)
                ||twoJudge(t1+t2,t3)
                ||twoJudge(t1-t2,t3)
                ||twoJudge(t2-t1,t3)
                ||twoJudge(t1*1.0/t2,t3)
                ||twoJudge(t2*1.0/t1,t3)
                ||twoJudge(t1*t3,t2)
                ||twoJudge(t1+t3,t2)
                ||twoJudge(t1-t3,t2)
                ||twoJudge(t3-t1,t2)
                ||twoJudge(t1*1.0/t3,t2)
                ||twoJudge(t3*1.0/t1,t2)
                ||twoJudge(t2*t3,t1)
                ||twoJudge(t2+t3,t1)
                ||twoJudge(t2-t3,t1)
                ||twoJudge(t3-t2,t1)
                ||twoJudge(t2*1.0/t3,t1)
                ||twoJudge(t3*1.0/t2,t1);

    }
    public boolean twoJudge(double t1, double t2){
        if(t1==0||t2==0){
            return false;
        }
        return oneJudge(t1 + t2)
                || oneJudge(t1 * t2)
                || oneJudge(t1 * 1.0 / t2)
                || oneJudge(t2*1.0 / t2)
                || oneJudge(t1 + t2)
                || oneJudge(t1 - t2);
    }

    public boolean oneJudge(double d){
        return (Math.abs(d - 24) < EPISON);
    }
    public static void main(String[] args) {
        Leetcode679 leetcode679 = new Leetcode679();
        boolean two1 = leetcode679.threeJudge(12,0,1);
        boolean two2 = leetcode679.threeJudge(11.3,10.7, 2);
        System.out.println("success!!");
    }
  }
